package GameObjects.Ships.Sheilds;

import java.awt.Graphics2D;
import java.awt.event.ActionListener;

import GUI.BottomPanel;
import GUI.Panels.GameObjectPanels.SheildPanel;
import GameObjects.Instances.Instances;
import GameObjects.Physics.Position;
import GameObjects.Ships.ShipObject;
import Logic.GameTime;

public abstract class Sheilds extends ShipObject
{
	private SheildPanel panel = null;;
	protected double energyPerSheild;
	protected GameTime downTime;
	protected boolean hasGoneDown = false;
	
	public Sheilds(Instances instances, Position position, double maxEnergyLevel, double energyPerSheild, int downTime)
	{
		super(instances, position, maxEnergyLevel);
		this.energyPerSheild = energyPerSheild;
		this.downTime = new GameTime(downTime);
	}
	
	public double rechargeEnegry(double energy)
	{
		if(panel != null)
			this.panel.update(Health());
		if(hasGoneDown)
			if(downTime.hasTickedOver())
				hasGoneDown = false;
			else
				return energy;
		double extra = addHealth(energy / this.energyPerSheild);
		if(panel != null)
			this.panel.update(Health());
		return extra;
	}
	
	@Override
	protected double damage(double damage)
	{
		double extra = super.damage(damage);
		if(this.Health() == 0)
			this.hasGoneDown = true;
		return extra;
	}
	
	@Override
	public void setPanel(ActionListener actionListener, BottomPanel panel)
	{
//		if(this.panel == null)
//			this.panel = new SheildPanel(actionListener, Health());
//		panel.addObjectPanelBottomRight(this.panel);
	}
}
